<?php
/**
 * Created by PhpStorm.
 * User: dy
 * Date: 2020/1/20
 * Time: 16:43
 */
namespace app\admin\controller;
use app\admin\model\AdminActionLogModel;
use app\common\controller\BackendController;
use think\facade\View;

class AdminActionLog extends BackendController
{
    /**
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index(){
        if($this->request->isAjax()){
            $this->model = AdminActionLogModel::instance();
            list($where,$sort,$order,$page,$limit) = $this->model->buildParams($this->request);
            $total = $this->model
                ->where($where)
                ->count();
            $list = $this->model
                ->with('Admin')
                ->where($where)
                ->page($page,$limit)
                ->order($sort,$order)
                ->visible(['Admin.username'])
                ->select();
            $this->success('查询成功','',['list'=>$list,'total'=>$total]);
        }
        $admin_list = \app\admin\model\Admin::instance()->column('id,username');
        View::assign('admin_list',$admin_list);
        return view();
    }
    /**
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function delete(){
        $ids = $this->request->param('ids/a');
        if(empty($ids)){
            $this->error('删除的数据不能为空！');
        }
        $res = AdminActionLogModel::destroy($ids,true);
        if (!$res) {
            $this->error('删除失败');
        }
        AdminActionLogModel::logAdd('删除权限组','权限组ids:'.json_encode($ids));
        $this->success('删除成功');
    }
}